<!DOCTYPE html>
</html>
<head>
    <meta charset="utf-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="renderer" content="webkit">
    <link rel="stylesheet" href="mdui/css/mdui.min.css">
    <script defer src="mdui/js/mdui.min.js"></script>
    <script src="js/axios.min.js"></script>
    <script src="js/qs.min.js"></script>
    <script src="js/common.js"></script>
    <script src="js/vue.js"></script>
    <script>
        //判断是否登录 如果未登录跳转到登录页面
        // axios.get("/student/online")
        //     .then(function (res) {
        //         if (!res.data.success) {
        //             mdui.alert("用户不在线请登录")
        //             window.setTimeout(function () {
        //                 window.location.href = 'login.html'
        //             }, 3000)
        //         }
        //     });
        //退出
        function logout() {
            console.log(123)
            axios.get("student/logout")
                .then(function (res) {
                    if (res.data.success) {
                        window.location.href = 'login.html'
                    } else {
                        mdui.alert("操作失败")
                    }
                })
        }

        function tologin() {
            window.location.href = 'login.html'
        }
    </script>

    <style>
        .mdui-typo-title {
            margin: 0 auto;
        }

        .title {
            width: 100%;
            font-size: 24px;
            text-align: center;
        }


        .login {

            margin-right: 20px;
            width: 45px;
        }

        .refresh {

            width: 45px;
        }
    </style>
</head>
<body class="mdui-drawer-body-left
    mdui-appbar-with-toolbar
    mdui-theme-primary-indigo
    mdui-theme-accent-pink
    mdui-theme-layout-auto">

<div id="app">
    <header class="mdui-appbar mdui-appbar-fixed" id="mdui-header">
        <div class="mdui-toolbar mdui-color-theme">
            <span class="mdui-btn mdui-btn-icon mdui-ripple mdui-ripple-white"
                  mdui-drawer="{target: '#main-drawer', swipe: true}">
<!--                <i class="mdui-icon material-icons">menu</i>-->
            </span>

            <a href="" class="mdui-typo-title"></a>
            <div class="title">校园维修管理系统</div>
            <i class="mdui-icon material-icons login" @click="tologin">account_box</i>
            <i class="mdui-icon material-icons refresh " @click="refresh">refresh</i>
            <!--            <div class="mdui-toolbar-spacer"></div>-->
            <!--            <a onclick="logout()" target="_blank"-->
            <!--               class="mdui-btn mdui-btn-icon mdui-ripple mdui-ripple-white"-->
            <!--               mdui-tooltip="{content: '退出'}"-->
            <!--            >-->
            <!--                <i class="mdui-icon material-icons">exit_to_app</i>-->
            <!--            </a>-->
        </div>
    </header>


    <div class="mdui-container" style="margin-top: 24px;">
        <div class="mdui-textfield mdui-textfield-floating-label ">
            <h3>报修问题查询</h3>
        </div>
        <div class="mdui-textfield mdui-textfield-floating-label inputt">
            <i class="mdui-icon material-icons">search</i>
            <input class="detailinput" placeholder="搜索问题简述" v-model="detail1">
        </div>
        <div class="mdui-textfield mdui-textfield-floating-label ">
            <button class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-theme-accent but" @click="findrepaires">查询
            </button>
        </div>

        <!--    <button class="mdui-btn  button1 mdui-btn-raised mdui-ripple mdui-color-theme-accent but" @click="submitRepair">-->
        <!--        我要报修-->
        <!--    </button>-->

        <div class="mdui-table-fluid" v-if="flage" style="float: left">

            <table class="mdui-table">
                <thead>
                <tr>
                    <th>地点</th>
                    <th>状态</th>
                    <th>详情</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="(r,index) in repairs">
                    <td>{{r.place}}</td>
                    <td>{{r.status |fmtGenter }}</td>
                    <td>{{r.detail}}</td>

                </tr>
                </tbody>
            </table>
        </div>

        <form style="margin-top: 10px ; width: 300px" v-if="flag1">
            <div class="mdui-textfield">
                <i class="mdui-icon material-icons">details</i>
                <label class="mdui-textfield-label">故障详情</label>
                <input class=" mdui-textfield-input" type="text" v-model="detail" name="detail"/>
            </div>
            <!-- 固定标签 -->
            <div class="mdui-textfield">
                <i class="mdui-icon material-icons">place</i>
                <label class="mdui-textfield-label">故障地点</label>
                <input class="mdui-textfield-input" type="text" v-model="palce" name="place"/>
            </div>
            <!-- 固定标签 -->
            <div class="mdui-textfield">
                <i class="mdui-icon material-icons">account_circle</i>
                <label class="mdui-textfield-label">报修人</label>
                <input class="mdui-textfield-input" type="text" v-model="studentId" name="studentId"/>
            </div>
            <!-- 固定标签 -->
            <div class="mdui-textfield">
                <i class="mdui-icon material-icons">insert_photo</i>
                <label class="mdui-textfield-label">描述</label>
                <input class=" mdui-textfield-input" type="file" id="file" name="file"/>
            </div>
            <div style="text-align: center">
                <button @click="addrepair" class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-theme-accent">提交
                </button>
            </div>
        </form>

        <div class="container" v-show="flag2">
            暂无报修内容
        </div>
        <button @click="add" v-show="flag3"
                class="mdui-btn mdui-btn-icon mdui-btn-dense mdui-color-theme-accent mdui-ripple addbut">
            <i class="mdui-icon material-icons add">add</i>
        </button>

    </div>
</div>

<script>
    var vm = new Vue({
        el: "#app",
        data: {
            repairs: [],
            palce: '',
            detail: '',
            studentId: '',
            detail: '',
            detail1: '',
            flage: false,
            flag1: false,
            flag2: true,
            flag3: true,
        },
        created() {
            //this.findrepaires();
        },

        filters: {
            fmtGenter(val) {

                if (val == 1) {
                    return "未安排维修维修"
                } else if (val == 2) {
                    return "已安排检修"
                } else if (val == 3) {
                    return "待同意取消，"
                } else if (val == 4) {
                    return "已同意取消"
                } else if (val == 5) {
                    return "待验收"
                } else if (val == 6) {
                    return "已验收"
                }
            }
        },
        methods: {
            refresh() {
                window.location.href = "index.html";
            },
            tologin() {
                window.location.href = "login.html";
            },
            addrepair() {
                console.log(123)
                let _this = this;
                let fd = new FormData(document.forms[0])//form里的输入框要有name属性
                console.log(fd)
                axios.post("/repair/inaddRepair", fd)
                    .then(function (res) {
                        if (res.data.success) {
                            mdui.alert("新增成功");
                            _this.place = ''
                            _this.detail = ''
                            _this.fd = ''
                            _this.studentId = ''
                            _this.flag1 = false
                        }
                    })
            },
            add() {
                this.flage = false;
                this.flag1 = true;
                this.flag2 = false;
                this.flag3 = false;
            },
            submitRepair() {
                window.location = "login.html"
            },

            findrepaires() {
                if (this.detail1 == '' || this.detail1 == null)
                    return
                this.flag1 = false;
                this.flag2 = false;
                this.flag3 = false;
                let _this = this;
                axios.post("/repair/findbydetail?detail=" + this.detail1)
                    .then(function (res) {
                        _this.repairs = res.data
                        _this.flage = true;
                        _this.detail1 = ''
                    })
            },
        },

    })
</script>
</body>
</html>
<style>

    .container {
        position: relative;
        height: 400px;
        width: 350px;
        border: 1px solid #d6d6d6;
        margin-top: 10px;
        text-align: center;
        line-height: 300px;
    }

    .addbut {
        margin-top: -60px;
        margin-left: 300px;
        width: 15px;
    }

    .detailinput {
        border-radius: 5px;
        width: 200px;
        font-size: 12px;
        padding-left: 40px;
        height: 35px;
        margin-top: 35px;
    }

    .but {
        height: 30px;
        width: 30px;
        margin-top: 20px;
        border: 1px solid #0f0f0f;
        border-radius: 5px;
        margin-top: 37px;
    }


    .inputt {
        float: left;
        width: 250px;
    }


</style>